package com.sps.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.sps.business.domain.RemoveTemp;
import com.sps.common.annotation.RepeatSubmit;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sps.common.annotation.Log;
import com.sps.common.core.controller.BaseController;
import com.sps.common.core.domain.AjaxResult;
import com.sps.common.enums.BusinessType;
import com.sps.business.domain.CcStockinfoInfo;
import com.sps.business.service.ICcStockinfoInfoService;
import com.sps.common.utils.poi.ExcelUtil;
import com.sps.common.core.page.TableDataInfo;

/**
 * 库存信息Controller
 * 
 * @author 王超
 * @date 2025-01-08
 */
@RestController
@RequestMapping("/business/ccstockinfo")
public class CcStockinfoInfoController extends BaseController
{
    @Autowired
    private ICcStockinfoInfoService ccStockinfoInfoService;

    /**
     * 查询库存信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:ccstockinfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(CcStockinfoInfo ccStockinfoInfo)
    {
        startPage();
        List<CcStockinfoInfo> list = ccStockinfoInfoService.selectCcStockinfoInfoList(ccStockinfoInfo);
        return getDataTable(list);
    }

    /**
     * 导出库存信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:ccstockinfo:export')")
    @Log(title = "库存信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CcStockinfoInfo ccStockinfoInfo)
    {
        List<CcStockinfoInfo> list = ccStockinfoInfoService.selectCcStockinfoInfoList(ccStockinfoInfo);
        ExcelUtil<CcStockinfoInfo> util = new ExcelUtil<CcStockinfoInfo>(CcStockinfoInfo.class);
        util.exportExcel(response, list, "库存信息数据");
    }

    /**
     * 获取库存信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:ccstockinfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(ccStockinfoInfoService.selectCcStockinfoInfoById(id));
    }

    /**
     * 新增库存信息
     */
    @PreAuthorize("@ss.hasPermi('business:ccstockinfo:add')")
    @Log(title = "库存信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CcStockinfoInfo ccStockinfoInfo)
    {
        return toAjax(ccStockinfoInfoService.insertCcStockinfoInfo(ccStockinfoInfo));
    }

    /**
     * 修改库存信息
     */
    @PreAuthorize("@ss.hasPermi('business:ccstockinfo:edit')")
    @Log(title = "库存信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CcStockinfoInfo ccStockinfoInfo)
    {
        return toAjax(ccStockinfoInfoService.updateCcStockinfoInfo(ccStockinfoInfo));
    }

    /**
     * 删除库存信息
     */
    @PreAuthorize("@ss.hasPermi('business:ccstockinfo:remove')")
    @Log(title = "库存信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ccStockinfoInfoService.deleteCcStockinfoInfoByIds(ids));
    }

    /**
     * 扫码新增库存信息
     */
    @Log(title = "库存信息", businessType = BusinessType.INSERT)
    @RepeatSubmit(interval = 1000, message = "请求过于频繁")
    @PostMapping(value = "/addRemove")
    public AjaxResult addRemove(@RequestBody RemoveTemp temp)
    {
        return toAjax(ccStockinfoInfoService.insertTemp(temp));
    }

}
